package org.sais.eswn.deck;
/*
 * DeckEditorWindow.java
 *
 * Created on 2007/2/7 10:38
 */

import java.awt.event.ActionEvent;
import java.awt.event.MouseListener;
import java.io.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;
import javax.swing.event.ListSelectionListener;
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import org.sais.eswn.card.Card;
import org.sais.eswn.tool.Tools;
import org.sais.eswn.card.cardlabel.UniLabel;
import org.sais.eswn.tool.MyListModel;
import org.sais.eswn.ui.ListItem;
import org.sais.eswn.ui.MyCellRenderer;

/**
 *
 * @author  Romulus
 */
public class DeckEditorWindow extends javax.swing.JFrame {

    private JCheckBox[] colors;
    private JCheckBox[] atkattrs;
    private JCheckBox[] defattrs;
    private ArrayList<String> mCardList = new ArrayList<String>();
    private ArrayList<String> mDeckList = new ArrayList<String>();
    private Deck deck;
    private MouseListener clistClickAdapter;
    private MouseListener decklistClickAdapter;
    private String mDeckPath = null;
    String version;

    public DeckEditorWindow(String version) throws Exception {
        initComponents();
        //this.setIconImage(Toolkit.getDefaultToolkit().createImage(new ReadInnerFile("deckeditoricon.jpg").u));
        this.version = version;
        Initilize();
        loadList();
        applyFilters();
        showDeckList(-1);
        amount.setText(_clist.getModel().getSize() + Tools.getLoc(9));

        //this.setSize(800, 600);
        this.setVisible(true);

    }

    void Initilize() {
        colors = new JCheckBox[]{_spellwhite, _spellblue, _spellblack, _spellred, _spellgreen,
                    _eventwhite, _eventblue, _eventblack, _eventred, _eventgreen};
        atkattrs = new JCheckBox[]{_atka, _atkb, _atkc};
        defattrs = new JCheckBox[]{_defa, _defb, _defc};

        for (JCheckBox j : atkattrs) {
            j.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    applyFilters();
                }
            });
        }
        for (JCheckBox j : defattrs) {
            j.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    applyFilters();
                }
            });
        }

        for (JCheckBox j : colors) {
            j.addActionListener(new java.awt.event.ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    applyFilters();
                }
            });
        }

        _clistsort.add(_clistsortchar);
        _clistsort.add(_clistsortcost);
        _clistsort.add(_clistsortno);
    }

    void ShowCard(String cardno) {   //Translate flaged text into colored text
        Tools.showCard(cardno, _SCArea);
    }

    void loadList() {
        mCardList.addAll(Tools.listCardNos());
    /*DefaultListModel mod = new DefaultListModel();
    mod.removeAllElements();
    _clist.setModel(mod);
    _clist.setCellRenderer(new MyCellRenderer());

    for (Card c : Tools.getAllCards()) {
    switch (c.getType()) {
    case Card.CARDTYPE_EVENT:
    mod.addElement(new ListItem(new Color(0xC0C0FF), c.name, new UniLabel(null, c.no, false)));
    break;
    case Card.CARDTYPE_SPELL:
    mod.addElement(new ListItem(new Color(0xC0FFC0), c.name, new UniLabel(null, c.no, false)));
    break;
    default:
    break;
    }
    }

    _clist.setModel(mod);*/
    }

    void showFilteredList() {
        MyListModel mod = new MyListModel();
        mod.removeAllElements();
        _clist.setModel(mod);
        _clist.setCellRenderer(new MyCellRenderer());
        ListSelectionListener[] listeners = _clist.getListSelectionListeners();
        for (int k = 0; k < listeners.length; ++k) {
            _clist.removeListSelectionListener(listeners[k]);
        }

        for (String no : mCardList) {
            Card c = Tools.getCard(no);
            mod.addElementwithoutFire(new ListItem(c.getDisplayColor(), c.name, new UniLabel(null, no, false)));
        }
        mod.fire();
        for (int k = 0; k < listeners.length; ++k) {
            _clist.addListSelectionListener(listeners[k]);
        }
        _clist.setModel(mod);
        MouseListener[] ms = _clist.getMouseListeners();
        for (int i = 0; i < ms.length; ++i) {
            if (ms[i].equals(clistClickAdapter)) {
                _clist.removeMouseListener(ms[i]);
            }
        }
        clistClickAdapter = new java.awt.event.MouseAdapter() {

            @Override
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                dispatchShowCard(_clist, evt);
                if (_clist.locationToIndex(evt.getPoint()) >= 0) {
                    synchronizeList(0);
                }
                if (evt.getClickCount() >= 2) {
                    addtoDeck();
                }
            }
        };
        _clist.addMouseListener(clistClickAdapter);
    }

    void dispatchShowCard(JList list, MouseEvent evt) {
        int index = list.locationToIndex(evt.getPoint());
        if (index < 0) {
            return;
        }
        String cardno = ((ListItem) (list.getModel().getElementAt(index))).label.cardno;
        ShowCard(cardno);
    }

    void showSelected(JList list) {
        int index = list.getSelectedIndex();
        String cardno = ((ListItem) (list.getModel().getElementAt(index))).label.cardno;
        if (index >= 0) {
            ShowCard(cardno);
        }
    }

    void showDeckList(int setindex) {
        sortDeckList();

        DefaultListModel mod = new DefaultListModel();
        mod.removeAllElements();
        _decklist.setModel(mod);
        _decklist.setCellRenderer(new MyCellRenderer());
        for (String no : mDeckList) {
            Card c = Tools.getCard(no);
            mod.addElement(new ListItem(c.getDisplayColor(), c.name, new UniLabel(null, no, false)));
        }
        _decklist.setModel(mod);
        MouseListener[] ms = _decklist.getMouseListeners();
        for (int i = 0; i < ms.length; ++i) {
            if (ms[i].equals(decklistClickAdapter)) {
                _decklist.removeMouseListener(ms[i]);
            }
        }
        decklistClickAdapter = new java.awt.event.MouseAdapter() {

            @Override
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                dispatchShowCard(_decklist, evt);
                if (_decklist.locationToIndex(evt.getPoint()) >= 0) {
                    synchronizeList(1);
                }
                if (evt.getClickCount() >= 2) {
                    removefromDeck();
                }
            }
        };
        _decklist.addMouseListener(decklistClickAdapter);
        if (setindex >= 0) {
            _decklist.setSelectedIndex(setindex);
        }

        float totalCost = 0f;
        float totalEventCost = 0f;
        boolean[] color = {false, false, false, false, false};
        for (String no : mDeckList) {
            Card c = Tools.getCard(no);
            if (c.getType() == Card.CARDTYPE_SPELL) {
                totalCost += c.text.getCost();
            } else {
                // Event
                totalEventCost += c.text.getCost();
            }
            color[c.getColor()] = true;
        }
        int haveColor = 0;
        for (boolean b : color) {
            if (b) {
                haveColor++;
            }
        }
        String eventMax;
        switch (haveColor) {
            case 0:
            case 1:
                eventMax = "8.0";
                break;
            case 2:
                eventMax = "6.0";
                break;
            default:
                eventMax = "4.0";
                break;
        }
        _decksab.setText(Tools.parseLocale(15, new String[]{String.valueOf(totalCost)}));
        _decksabline2.setText(Tools.parseLocale(16, new String[]{String.valueOf(totalEventCost), eventMax}));
    }

    private void sortDeckList() {
        /**
         * Transform to numbers, sort, then inverse transform.
         */
        final int BASE = 10000;
        final int EVENTBASE = 50000;
        ArrayList<Integer> transform = new ArrayList<Integer>(mDeckList.size());
        HashMap<Character, Integer> map = new HashMap<Character, Integer>();
        map.put('W', 0);
        map.put('U', 1);
        map.put('B', 2);
        map.put('R', 3);
        map.put('G', 4);
        for (String no : mDeckList) {
            int num = -1;
            if (no.charAt(0) == 'V') {
                // Event
                num = EVENTBASE + map.get(no.charAt(1)) * BASE + Integer.parseInt(no.substring(2));
            } else {
                // Spell
                num = map.get(no.charAt(0)) * BASE + Integer.parseInt(no.substring(1));
            }
            transform.add(num);
        }
        Collections.sort(transform);
        mDeckList.clear();

        HashMap<Integer, Character> inv = new HashMap<Integer, Character>();
        for (Character c : map.keySet()) {
            inv.put(map.get(c), c);
        }
        for (Integer i : transform) {
            // Type
            String type = "";
            if (i >= EVENTBASE) {
                type = "V";
                i -= EVENTBASE;
            }
            // Color
            Character color = inv.get(i / BASE);

            String no = type + color + (i % BASE);
            mDeckList.add(no);
        }
    }

    private void synchronizeList(int acter) {   //0:CardList 1:DeckList
        JList act;
        JList sync;
        ArrayList<String> actlist;
        ArrayList<String> synclist;
        if (acter == 0) {
            act = _clist;
            actlist = mCardList;
            sync = _decklist;
            synclist = mDeckList;
        } else {
            act = _decklist;
            actlist = mDeckList;
            sync = _clist;
            synclist = mCardList;
        }
        if (act.getSelectedIndex() < 0) {
            return;
        }
        int index = synclist.indexOf(actlist.get(act.getSelectedIndex()));
        if (index >= 0) {
            sync.setSelectedIndex(index);
            sync.ensureIndexIsVisible(index);
        }
    }

    void applyFilters() {
        applyColorFilter();
        applyAttrFilter();

        sortCardList();
        showFilteredList();
        amount.setText(_clist.getModel().getSize() + Tools.getLoc(9));
    }

    //Start of Filters
    private void applyColorFilter() {
        mCardList = new ArrayList<String>();

        for (int i = 0; i < colors.length; ++i) {
            if (colors[i].isSelected()) {
                fillColorList(i, mCardList);
            }
        }
    }

    private void applyAttrFilter() {
        ArrayList<String> list = new ArrayList<String>();
        for (String no : mCardList) {
            Card c = Tools.getCard(no);
            boolean fit = true;
            for (int i = 0; i < 3; ++i) {
                if (atkattrs[i].isSelected()) {
                    if (!c.text.getFire().hasBullet(i)) {
                        fit = false;
                        break;
                    }
                }
                if (defattrs[i].isSelected()) {
                    if (!c.text.getConquer().hasBullet(i)) {
                        fit = false;
                        break;
                    }
                }
            }
            if (fit) {
                list.add(no);
            }
        }
        mCardList.clear();
        mCardList.addAll(list);
    }

    //end of Filters
    private void fillColorList(int index, ArrayList<String> list) {
        String prefix = "";
        switch (index) {
            case 0:
                prefix = "W";
                break;
            case 1:
                prefix = "U";
                break;
            case 2:
                prefix = "B";
                break;
            case 3:
                prefix = "R";
                break;
            case 4:
                prefix = "G";
                break;
            case 5:
                prefix = "VW";
                break;
            case 6:
                prefix = "VU";
                break;
            case 7:
                prefix = "VB";
                break;
            case 8:
                prefix = "VR";
                break;
            case 9:
                prefix = "VG";
                break;
            default:
                break;
        }

        for (int seq = 1; seq < 9999; ++seq) {
            String fetch = prefix + seq;
            if (Tools.getCardDataBase().containsKey(fetch)) {
                list.add(fetch);
            } else {
                break;
            }
        }
    }

    private void sortCardList() {
        if (_clistsortno.isSelected()) {
            Collections.sort(mCardList, new Comparator<String>() {

                public int compare(String o1, String o2) {
                    Card c1 = Tools.getCard(o1);
                    Card c2 = Tools.getCard(o2);
                    if (c1.getColor() != c2.getColor()) {
                        return c1.getColor() - c2.getColor();
                    }
                    if (c1.getType() != c2.getType()) {
                        return c1.getType() - c2.getType();
                    }
                    return c1.getNumber() - c2.getNumber();
                }
            });
        } else if (_clistsortchar.isSelected()) {
            Collections.sort(mCardList, new Comparator<String>() {

                public int compare(String o1, String o2) {
                    Card c1 = Tools.getCard(o1);
                    Card c2 = Tools.getCard(o2);
                    if (!c1.text.getUser().equals(c2.text.getUser())) {
                        return c1.text.getUser().compareTo(c2.text.getUser());
                    }
                    if (c1.getType() != c2.getType()) {
                        return c1.getType() - c2.getType();
                    }
                    if (c1.text.getCost() != c2.text.getCost()) {
                        return (int) (2 * c1.text.getCost() - 2 * c2.text.getCost());
                    }
                    if (c1.getColor() != c2.getColor()) {
                        return c1.getColor() - c2.getColor();
                    }
                    return c1.getNumber() - c2.getNumber();
                }
            });
        } else if (_clistsortcost.isSelected()) {
            Collections.sort(mCardList, new Comparator<String>() {

                public int compare(String o1, String o2) {
                    Card c1 = Tools.getCard(o1);
                    Card c2 = Tools.getCard(o2);
                    if (c1.getType() != c2.getType()) {
                        return c1.getType() - c2.getType();
                    }
                    if (c1.text.getCost() != c2.text.getCost()) {
                        return (int) (2 * c1.text.getCost() - 2 * c2.text.getCost());
                    }
                    if (c1.getColor() != c2.getColor()) {
                        return c1.getColor() - c2.getColor();
                    }
                    return c1.getNumber() - c2.getNumber();
                }
            });
        }
    }

    private void addtoDeck() {
        if (_clist.getSelectedIndex() < 0) {
            return;
        }
        String no = mCardList.get(_clist.getSelectedIndex());
        if (!mDeckList.contains(no)) {
            mDeckList.add(no);
        }
        showDeckList(-1);
        synchronizeList(0);
    }

    private void removefromDeck() {
        int index = _decklist.getSelectedIndex();
        if (index < 0) {
            return;
        }
        mDeckList.remove(index);
        showDeckList(index);
        synchronizeList(1);
    }

    void newDeck() {
        mDeckList.clear();
        _deckname.setText("New Deck");
        deck = new Deck(_deckname.getText(), new ArrayList<String>(), new ArrayList<String>());
        showDeckList(-1);
    }

    void loadDeck() {
        JFileChooser chooser = new JFileChooser();
        File f;
        String sdir = Tools.readConfig("lastdeckfolder");
        if (sdir.equals("")) {
            sdir = "deck";
        }
        if (new File(sdir).exists()) {
            f = new File(sdir);
        } else {
            f = new File(".");
        }
        chooser.setCurrentDirectory(f);
        chooser.setAcceptAllFileFilterUsed(true);
        chooser.addChoosableFileFilter(new decFilter());

        int result = chooser.showOpenDialog(this);
        if (result == JFileChooser.CANCEL_OPTION) {
            return;
        }
        try {
            newDeck();
            File file = chooser.getSelectedFile();
            Tools.updateConfig("lastdeckfolder", file.getParent());
            mDeckPath = file.getPath();
            deck = Deck.load(file);
            _deckname.setText(deck.getDeckname());
            mDeckList.addAll(deck.listCardnos());
            showDeckList(-1);
        } catch (Exception e) {
            e.printStackTrace();
            JOptionPane.showMessageDialog(this, Tools.getLoc(10));
        }
    }

    boolean checkDeck() {
        return true;
    }

    boolean checkCharCard(int cardnum) {
        if (cardnum % 100 == 0 || cardnum == 8001 || cardnum == 8002 || cardnum == 8101) {
            return true;
        } else {
            return false;
        }
    }

    void saveDeck() {
        if (!checkDeck()) {
            return;
        }
        JFileChooser chooser = new JFileChooser();
        String sdir = Tools.readConfig("lastdeckfolder");
        if (sdir.equals("")) {
            sdir = "deck";
        }
        if (!new File(sdir).exists()) {
            new File(sdir).mkdir();
        }
        chooser.setCurrentDirectory(new File(sdir));
        chooser.setAcceptAllFileFilterUsed(true);
        chooser.addChoosableFileFilter(new decFilter());
        if (mDeckPath == null) {
            chooser.setSelectedFile(new File(_deckname.getText() + ".dec"));
        } else {
            chooser.setSelectedFile(new File(mDeckPath));
        }
        int result = chooser.showSaveDialog(this);
        if (result == JFileChooser.CANCEL_OPTION) {
            return;
        }
        if (chooser.getFileFilter() instanceof decFilter) {
            //Deck File
            //Convert dlist to deck
            deck = new Deck();
            try {
                File file = chooser.getSelectedFile();
                if (file.getName().length() < 4) {
                    file = new File(file.getPath() + ".dec");
                } else if (!file.getName().substring(file.getName().length() - 4).endsWith(".dec")) {
                    file = new File(file.getPath() + ".dec");
                }
                Tools.updateConfig("lastdeckfolder", file.getParent());
                mDeckPath = file.getPath();
                deck.setDeckname(_deckname.getText());
                for (String no : mDeckList) {
                    deck.add(no);
                }
                deck.save(file);
                JOptionPane.showMessageDialog(null, file.getName() + Tools.getLoc(11));
            } catch (Exception e) {
                e.printStackTrace();
                JOptionPane.showMessageDialog(this, Tools.getLoc(10));
            }
        } else {
            //Plain Text File
            try {
                File file = chooser.getSelectedFile();
                if (file.getName().length() < 4) {
                    file = new File(file.getPath() + ".txt");
                } else if (!file.getName().substring(file.getName().length() - 4).endsWith(".txt")) {
                    file = new File(file.getPath() + ".txt");
                }
                BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8"));
                for (int i = 0; i < _decklist.getModel().getSize(); ++i) {
                    out.write(((ListItem) (_decklist.getModel().getElementAt(i))).getValue() + "\r\n");
                }
                out.close();
                JOptionPane.showMessageDialog(null, file.getName() + Tools.getLoc(11));
            } catch (Exception e) {
                e.printStackTrace();
                JOptionPane.showMessageDialog(this, Tools.getLoc(10));
            }
        }
    }

    void showTextDeck() {
        JTextArea jmessage = new JTextArea("");
        JScrollPane js = new JScrollPane(jmessage);
        js.setPreferredSize(new Dimension(100, 350));

        String message = "";
        for (int i = 0; i < _decklist.getModel().getSize(); ++i) {
            message += (((ListItem) (_decklist.getModel().getElementAt(i))).getValue() + "\r\n");
        }
        jmessage.setText(message);

        JOptionPane.showMessageDialog(this, js, "TEXT FORM DECK", JOptionPane.INFORMATION_MESSAGE);
    }
    /*
    void transfer() {
    JTextArea jdeck = new JTextArea("");
    JScrollPane js = new JScrollPane(jdeck);
    js.setPreferredSize(new Dimension(100, 350));
    JOptionPane.showMessageDialog(this, js, "TRANSFER FROM TEXT", JOptionPane.QUESTION_MESSAGE);
    String txt = jdeck.getText();
    if (txt.length() < 5) {
    return;
    }

    newDeck();
    String[] lines = txt.split("\n");
    for (String line : lines) {
    String[] s;
    if (line.startsWith("Leader")) {
    s = line.split(" ");
    if (s.length == 4) {
    s[2] += " " + s[3];
    }
    int cardnum = findCard(s[2]);
    if (cardnum > 0) {
    leader = cardnum;
    dlist[dlistcnt] = cardnum;
    camount[cardnum] += Tools.safeParseInt(s[1].substring(2, 3));
    ++dlistcnt;
    }
    } else if (line.startsWith("Lv")) {
    s = line.split(" ");
    if (s.length == 3) {
    s[1] += " " + s[2];
    }
    int cardnum = findCard(s[1]);
    if (cardnum > 0) {
    dlist[dlistcnt] = cardnum;
    camount[cardnum] += Tools.safeParseInt(s[0].substring(2, 3));
    ++dlistcnt;
    }
    } else if (line.length() > 1) {
    if (line.charAt(1) == 'x') {
    s = line.split(" ");
    if (s.length == 3) {
    s[1] += " " + s[2];
    }
    int cardnum = findCard(s[1]);
    if (cardnum > 0) {
    dlist[dlistcnt] = cardnum;
    camount[cardnum] += Tools.safeParseInt(s[0].substring(0, 1));
    ++dlistcnt;
    }
    } else if (line.charAt(2) == 'x') {
    //Wiki Form
    s = line.split(" ");
    int cardnum = findCard(s[2].substring(1, s[2].length() - 1));
    if (cardnum > 0) {
    dlist[dlistcnt] = cardnum;
    camount[cardnum] += Tools.safeParseInt(s[0]);
    ++dlistcnt;
    }
    }
    }
    }

    showDeckList(-1);
    }

    int findCard(String cardname) {
    for (Card c : Tools.cdata) {
    if (c == null) {
    continue;
    }
    if (cardname.equals(c.CardName)) {
    return c.CardNumber;
    }

    }
    return -1;
    }
     */

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents() {

    _clistsort = new javax.swing.ButtonGroup();
    jScrollPane1 = new javax.swing.JScrollPane();
    _SCArea = new javax.swing.JTextPane();
    jScrollPane2 = new javax.swing.JScrollPane();
    _clist = new javax.swing.JList();
    jScrollPane3 = new javax.swing.JScrollPane();
    _decklist = new javax.swing.JList();
    _deckname = new javax.swing.JTextField();
    allcheck = new javax.swing.JButton();
    alluncheck = new javax.swing.JButton();
    savedeck = new javax.swing.JButton();
    loaddeck = new javax.swing.JButton();
    newdeck = new javax.swing.JButton();
    amount = new javax.swing.JLabel();
    _decksab = new javax.swing.JLabel();
    _clistsortchar = new javax.swing.JRadioButton();
    jLabel20 = new javax.swing.JLabel();
    _cardtab = new javax.swing.JTabbedPane();
    _spellpanel = new javax.swing.JPanel();
    jLabel21 = new javax.swing.JLabel();
    jLabel22 = new javax.swing.JLabel();
    _spellwhite = new javax.swing.JCheckBox();
    _eventwhite = new javax.swing.JCheckBox();
    _spellblue = new javax.swing.JCheckBox();
    _eventblue = new javax.swing.JCheckBox();
    _spellblack = new javax.swing.JCheckBox();
    _eventblack = new javax.swing.JCheckBox();
    _spellred = new javax.swing.JCheckBox();
    _eventred = new javax.swing.JCheckBox();
    _spellgreen = new javax.swing.JCheckBox();
    _eventgreen = new javax.swing.JCheckBox();
    _showtextdeck = new javax.swing.JButton();
    _transfer = new javax.swing.JButton();
    _decksabline2 = new javax.swing.JLabel();
    _clistsortno = new javax.swing.JRadioButton();
    _clistsortcost = new javax.swing.JRadioButton();
    _attrtab = new javax.swing.JTabbedPane();
    _spellpanel1 = new javax.swing.JPanel();
    jLabel23 = new javax.swing.JLabel();
    jLabel24 = new javax.swing.JLabel();
    _atka = new javax.swing.JCheckBox();
    _defa = new javax.swing.JCheckBox();
    _atkb = new javax.swing.JCheckBox();
    _defb = new javax.swing.JCheckBox();
    _atkc = new javax.swing.JCheckBox();
    _defc = new javax.swing.JCheckBox();
    _attrallcheck = new javax.swing.JButton();
    _attralluncheck = new javax.swing.JButton();
    jMenuBar6 = new javax.swing.JMenuBar();
    jMenu1 = new javax.swing.JMenu();
    _checkrule = new javax.swing.JMenuItem();
    _export = new javax.swing.JMenu();
    jMenuItem1 = new javax.swing.JMenuItem();
    jMenu6 = new javax.swing.JMenu();
    closeeditor5 = new javax.swing.JMenuItem();
    quit5 = new javax.swing.JMenuItem();

    setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
    setTitle("東方銀翼札デッキエディター");
    setFont(new java.awt.Font("ＭＳ Ｐゴシック", 0, 12));
    addWindowListener(new java.awt.event.WindowAdapter() {
      public void windowClosed(java.awt.event.WindowEvent evt) {
        formWindowClosed(evt);
      }
    });

    _SCArea.setFont(new java.awt.Font("ＭＳ Ｐゴシック", 0, 12));
    jScrollPane1.setViewportView(_SCArea);

    _clist.setFont(new java.awt.Font("ＭＳ Ｐゴシック", 0, 12));
    _clist.setModel(new javax.swing.AbstractListModel() {
      String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
      public int getSize() { return strings.length; }
      public Object getElementAt(int i) { return strings[i]; }
    });
    _clist.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
      public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
        _clistValueChanged(evt);
      }
    });
    _clist.addKeyListener(new java.awt.event.KeyAdapter() {
      public void keyPressed(java.awt.event.KeyEvent evt) {
        _clistKeyPressed(evt);
      }
    });
    jScrollPane2.setViewportView(_clist);

    _decklist.setFont(new java.awt.Font("ＭＳ Ｐゴシック", 0, 12));
    _decklist.setModel(new javax.swing.AbstractListModel() {
      String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
      public int getSize() { return strings.length; }
      public Object getElementAt(int i) { return strings[i]; }
    });
    _decklist.setVisibleRowCount(40);
    _decklist.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
      public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
        _decklistValueChanged(evt);
      }
    });
    _decklist.addKeyListener(new java.awt.event.KeyAdapter() {
      public void keyPressed(java.awt.event.KeyEvent evt) {
        _decklistKeyPressed(evt);
      }
    });
    jScrollPane3.setViewportView(_decklist);

    _deckname.setFont(new java.awt.Font("ＭＳ Ｐゴシック", 0, 12));
    _deckname.setText("NEW DECK");
    _deckname.setPreferredSize(new java.awt.Dimension(228, 19));
    _deckname.addFocusListener(new java.awt.event.FocusAdapter() {
      public void focusGained(java.awt.event.FocusEvent evt) {
        _decknameFocusGained(evt);
      }
    });

    allcheck.setFont(new java.awt.Font("ＭＳ Ｐゴシック", 0, 12));
    allcheck.setText("全て選択");
    allcheck.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        allcheckActionPerformed(evt);
      }
    });

    alluncheck.setFont(new java.awt.Font("ＭＳ Ｐゴシック", 0, 12));
    alluncheck.setText("全て外す");
    alluncheck.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        alluncheckActionPerformed(evt);
      }
    });

    savedeck.setFont(new java.awt.Font("ＭＳ Ｐゴシック", 0, 12));
    savedeck.setText("SAVE");
    savedeck.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        savedeckActionPerformed(evt);
      }
    });

    loaddeck.setFont(new java.awt.Font("ＭＳ Ｐゴシック", 0, 12));
    loaddeck.setText("LOAD");
    loaddeck.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        loaddeckActionPerformed(evt);
      }
    });

    newdeck.setFont(new java.awt.Font("ＭＳ Ｐゴシック", 0, 12));
    newdeck.setText("NEW");
    newdeck.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        newdeckActionPerformed(evt);
      }
    });

    amount.setFont(new java.awt.Font("MS PGothic", 0, 12));
    amount.setText("281枚");

    _decksab.setFont(new java.awt.Font("ＭＳ Ｐゴシック", 0, 12));
    _decksab.setText("スペルコスト");

    _clistsortchar.setFont(new java.awt.Font("ＭＳ Ｐゴシック", 0, 12));
    _clistsortchar.setText("キャラ");
    _clistsortchar.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
    _clistsortchar.setMargin(new java.awt.Insets(0, 0, 0, 0));
    _clistsortchar.addItemListener(new java.awt.event.ItemListener() {
      public void itemStateChanged(java.awt.event.ItemEvent evt) {
        _clistsortcharItemStateChanged(evt);
      }
    });

    jLabel20.setFont(new java.awt.Font("ＭＳ Ｐゴシック", 0, 12));
    jLabel20.setText("Sorted by:");

    _cardtab.setFont(new java.awt.Font("ＭＳ Ｐゴシック", 0, 12));

    _spellpanel.setLayout(new java.awt.GridLayout(6, 3));

    jLabel21.setFont(new java.awt.Font("ＭＳ Ｐゴシック", 0, 12));
    jLabel21.setText("スペル");
    _spellpanel.add(jLabel21);

    jLabel22.setFont(new java.awt.Font("ＭＳ Ｐゴシック", 0, 12));
    jLabel22.setText("イベント");
    _spellpanel.add(jLabel22);

    _spellwhite.setFont(new java.awt.Font("MS PGothic", 0, 12));
    _spellwhite.setSelected(true);
    _spellwhite.setText("白");
    _spellwhite.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
    _spellwhite.setMargin(new java.awt.Insets(0, 0, 0, 0));
    _spellwhite.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        _spellwhiteActionPerformed(evt);
      }
    });
    _spellpanel.add(_spellwhite);

    _eventwhite.setFont(new java.awt.Font("MS PGothic", 0, 12));
    _eventwhite.setSelected(true);
    _eventwhite.setText("白");
    _eventwhite.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
    _eventwhite.setMargin(new java.awt.Insets(0, 0, 0, 0));
    _eventwhite.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        _eventwhiteActionPerformed(evt);
      }
    });
    _spellpanel.add(_eventwhite);

    _spellblue.setFont(new java.awt.Font("MS PGothic", 0, 12));
    _spellblue.setSelected(true);
    _spellblue.setText("青");
    _spellblue.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
    _spellblue.setMargin(new java.awt.Insets(0, 0, 0, 0));
    _spellblue.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        _spellblueActionPerformed(evt);
      }
    });
    _spellpanel.add(_spellblue);

    _eventblue.setFont(new java.awt.Font("MS PGothic", 0, 12));
    _eventblue.setSelected(true);
    _eventblue.setText("青");
    _eventblue.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
    _eventblue.setMargin(new java.awt.Insets(0, 0, 0, 0));
    _eventblue.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        _eventblueActionPerformed(evt);
      }
    });
    _spellpanel.add(_eventblue);

    _spellblack.setFont(new java.awt.Font("MS PGothic", 0, 12));
    _spellblack.setSelected(true);
    _spellblack.setText("黒");
    _spellblack.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
    _spellblack.setMargin(new java.awt.Insets(0, 0, 0, 0));
    _spellpanel.add(_spellblack);

    _eventblack.setFont(new java.awt.Font("MS PGothic", 0, 12));
    _eventblack.setSelected(true);
    _eventblack.setText("黒");
    _eventblack.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
    _eventblack.setMargin(new java.awt.Insets(0, 0, 0, 0));
    _spellpanel.add(_eventblack);

    _spellred.setFont(new java.awt.Font("MS PGothic", 0, 12)); // NOI18N
    _spellred.setSelected(true);
    _spellred.setText("紅");
    _spellred.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
    _spellred.setMargin(new java.awt.Insets(0, 0, 0, 0));
    _spellred.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        _spellredActionPerformed(evt);
      }
    });
    _spellpanel.add(_spellred);

    _eventred.setFont(new java.awt.Font("MS PGothic", 0, 12));
    _eventred.setSelected(true);
    _eventred.setText("紅");
    _eventred.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
    _eventred.setMargin(new java.awt.Insets(0, 0, 0, 0));
    _eventred.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        _eventredActionPerformed(evt);
      }
    });
    _spellpanel.add(_eventred);

    _spellgreen.setFont(new java.awt.Font("MS PGothic", 0, 12));
    _spellgreen.setSelected(true);
    _spellgreen.setText("緑");
    _spellgreen.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
    _spellgreen.setMargin(new java.awt.Insets(0, 0, 0, 0));
    _spellpanel.add(_spellgreen);

    _eventgreen.setFont(new java.awt.Font("MS PGothic", 0, 12));
    _eventgreen.setSelected(true);
    _eventgreen.setText("緑");
    _eventgreen.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
    _eventgreen.setMargin(new java.awt.Insets(0, 0, 0, 0));
    _spellpanel.add(_eventgreen);

    _cardtab.addTab("カード", _spellpanel);

    _showtextdeck.setFont(new java.awt.Font("ＭＳ Ｐゴシック", 0, 12));
    _showtextdeck.setText("TEXT");
    _showtextdeck.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        _showtextdeckActionPerformed(evt);
      }
    });

    _transfer.setFont(new java.awt.Font("ＭＳ Ｐゴシック", 0, 12));
    _transfer.setText("TRANSFER");
    _transfer.setEnabled(false);
    _transfer.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        _transferActionPerformed(evt);
      }
    });

    _decksabline2.setFont(new java.awt.Font("ＭＳ Ｐゴシック", 0, 12));
    _decksabline2.setText("イベントコスト");

    _clistsortno.setFont(new java.awt.Font("ＭＳ Ｐゴシック", 0, 12));
    _clistsortno.setSelected(true);
    _clistsortno.setText("色");
    _clistsortno.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
    _clistsortno.setMargin(new java.awt.Insets(0, 0, 0, 0));
    _clistsortno.addItemListener(new java.awt.event.ItemListener() {
      public void itemStateChanged(java.awt.event.ItemEvent evt) {
        _clistsortnoItemStateChanged(evt);
      }
    });

    _clistsortcost.setFont(new java.awt.Font("ＭＳ Ｐゴシック", 0, 12));
    _clistsortcost.setText("コスト");
    _clistsortcost.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
    _clistsortcost.setMargin(new java.awt.Insets(0, 0, 0, 0));
    _clistsortcost.addItemListener(new java.awt.event.ItemListener() {
      public void itemStateChanged(java.awt.event.ItemEvent evt) {
        _clistsortcostItemStateChanged(evt);
      }
    });

    _attrtab.setFont(new java.awt.Font("ＭＳ Ｐゴシック", 0, 12));

    _spellpanel1.setLayout(new java.awt.GridLayout(6, 3));

    jLabel23.setFont(new java.awt.Font("ＭＳ Ｐゴシック", 0, 12));
    jLabel23.setText("弾幕");
    _spellpanel1.add(jLabel23);

    jLabel24.setFont(new java.awt.Font("ＭＳ Ｐゴシック", 0, 12));
    jLabel24.setText("攻略");
    _spellpanel1.add(jLabel24);

    _atka.setFont(new java.awt.Font("MS PGothic", 0, 12)); // NOI18N
    _atka.setText("A密");
    _atka.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
    _atka.setMargin(new java.awt.Insets(0, 0, 0, 0));
    _atka.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        _atkaActionPerformed(evt);
      }
    });
    _spellpanel1.add(_atka);

    _defa.setFont(new java.awt.Font("MS PGothic", 0, 12)); // NOI18N
    _defa.setText("A密");
    _defa.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
    _defa.setMargin(new java.awt.Insets(0, 0, 0, 0));
    _defa.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        _defaActionPerformed(evt);
      }
    });
    _spellpanel1.add(_defa);

    _atkb.setFont(new java.awt.Font("MS PGothic", 0, 12)); // NOI18N
    _atkb.setText("B速");
    _atkb.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
    _atkb.setMargin(new java.awt.Insets(0, 0, 0, 0));
    _atkb.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        _atkbActionPerformed(evt);
      }
    });
    _spellpanel1.add(_atkb);

    _defb.setFont(new java.awt.Font("MS PGothic", 0, 12)); // NOI18N
    _defb.setText("B速");
    _defb.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
    _defb.setMargin(new java.awt.Insets(0, 0, 0, 0));
    _defb.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        _defbActionPerformed(evt);
      }
    });
    _spellpanel1.add(_defb);

    _atkc.setFont(new java.awt.Font("MS PGothic", 0, 12)); // NOI18N
    _atkc.setText("C強");
    _atkc.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
    _atkc.setMargin(new java.awt.Insets(0, 0, 0, 0));
    _spellpanel1.add(_atkc);

    _defc.setFont(new java.awt.Font("MS PGothic", 0, 12)); // NOI18N
    _defc.setText("C強");
    _defc.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
    _defc.setMargin(new java.awt.Insets(0, 0, 0, 0));
    _defc.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        _defcActionPerformed(evt);
      }
    });
    _spellpanel1.add(_defc);

    _attrtab.addTab("属性", _spellpanel1);

    _attrallcheck.setFont(new java.awt.Font("ＭＳ Ｐゴシック", 0, 12));
    _attrallcheck.setText("全て選択");
    _attrallcheck.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        _attrallcheckActionPerformed(evt);
      }
    });

    _attralluncheck.setFont(new java.awt.Font("ＭＳ Ｐゴシック", 0, 12));
    _attralluncheck.setText("全て外す");
    _attralluncheck.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        _attralluncheckActionPerformed(evt);
      }
    });

    jMenu1.setText("ルール確認");
    jMenu1.setFont(new java.awt.Font("ＭＳ Ｐゴシック", 0, 12));

    _checkrule.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_R, java.awt.event.InputEvent.CTRL_MASK));
    _checkrule.setFont(new java.awt.Font("ＭＳ Ｐゴシック", 0, 12));
    _checkrule.setText("ルールページを開く");
    _checkrule.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        _checkruleActionPerformed(evt);
      }
    });
    jMenu1.add(_checkrule);

    jMenuBar6.add(jMenu1);

    _export.setText("Export");
    _export.setFont(new java.awt.Font("ＭＳ Ｐゴシック", 0, 12));
    _export.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        _exportActionPerformed(evt);
      }
    });

    jMenuItem1.setFont(new java.awt.Font("ＭＳ Ｐゴシック", 0, 12));
    jMenuItem1.setText("カードリスト");
    jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jMenuItem1ActionPerformed(evt);
      }
    });
    _export.add(jMenuItem1);

    jMenuBar6.add(_export);

    jMenu6.setText("終了");
    jMenu6.setFont(new java.awt.Font("ＭＳ Ｐゴシック", 0, 12));

    closeeditor5.setFont(new java.awt.Font("ＭＳ Ｐゴシック", 0, 12));
    closeeditor5.setText("デッキエディターを閉じる");
    closeeditor5.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        closeeditorActionPerformed(evt);
      }
    });
    jMenu6.add(closeeditor5);

    quit5.setFont(new java.awt.Font("ＭＳ Ｐゴシック", 0, 12));
    quit5.setText("ゲーム終了");
    quit5.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        quitActionPerformed(evt);
      }
    });
    jMenu6.add(quit5);

    jMenuBar6.add(jMenu6);

    setJMenuBar(jMenuBar6);

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(layout.createSequentialGroup()
        .addContainerGap()
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGroup(layout.createSequentialGroup()
            .addComponent(jLabel20)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(_clistsortchar)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(_clistsortcost)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(_clistsortno)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(amount))
          .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 240, javax.swing.GroupLayout.PREFERRED_SIZE))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addComponent(alluncheck)
          .addGroup(layout.createSequentialGroup()
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 257, javax.swing.GroupLayout.PREFERRED_SIZE)
              .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                  .addComponent(_cardtab, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)
                  .addComponent(allcheck))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                  .addComponent(_attrallcheck)
                  .addComponent(_attrtab, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)
                  .addComponent(_attralluncheck))))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 235, javax.swing.GroupLayout.PREFERRED_SIZE)
              .addComponent(_decksab)
              .addComponent(_decksabline2)
              .addGroup(layout.createSequentialGroup()
                .addComponent(savedeck)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(loaddeck)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(newdeck))
              .addGroup(layout.createSequentialGroup()
                .addComponent(_showtextdeck)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(_transfer))
              .addComponent(_deckname, javax.swing.GroupLayout.DEFAULT_SIZE, 235, Short.MAX_VALUE))))
        .addContainerGap())
    );
    layout.setVerticalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(layout.createSequentialGroup()
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
          .addGroup(layout.createSequentialGroup()
            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 260, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
              .addComponent(_cardtab, javax.swing.GroupLayout.PREFERRED_SIZE, 167, javax.swing.GroupLayout.PREFERRED_SIZE)
              .addComponent(_attrtab, javax.swing.GroupLayout.PREFERRED_SIZE, 167, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
              .addComponent(allcheck)
              .addComponent(_attrallcheck)))
          .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 460, javax.swing.GroupLayout.PREFERRED_SIZE)
          .addGroup(layout.createSequentialGroup()
            .addComponent(_deckname, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(jScrollPane3, 0, 0, Short.MAX_VALUE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(_decksab, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(_decksabline2, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
              .addComponent(savedeck)
              .addComponent(loaddeck)
              .addComponent(newdeck))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
              .addComponent(_showtextdeck)
              .addComponent(_transfer))
            .addGap(8, 8, 8)))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(alluncheck)
          .addComponent(_attralluncheck)
          .addComponent(jLabel20)
          .addComponent(_clistsortchar)
          .addComponent(_clistsortcost)
          .addComponent(_clistsortno)
          .addComponent(amount))
        .addGap(19, 19, 19))
    );

    pack();
  }// </editor-fold>//GEN-END:initComponents

  private void _decknameFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event__decknameFocusGained
      _deckname.setSelectionStart(0);
      _deckname.setSelectionEnd(_deckname.getText().length());
}//GEN-LAST:event__decknameFocusGained

   private void newdeckActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newdeckActionPerformed
       mDeckPath = null;
       newDeck();
   }//GEN-LAST:event_newdeckActionPerformed

   private void loaddeckActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loaddeckActionPerformed
       loadDeck();

   }//GEN-LAST:event_loaddeckActionPerformed

   private void savedeckActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_savedeckActionPerformed
       saveDeck();

   }//GEN-LAST:event_savedeckActionPerformed

   private void alluncheckActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_alluncheckActionPerformed
       for (JCheckBox j : colors) {
           j.setSelected(false);
       }

       applyFilters();
   }//GEN-LAST:event_alluncheckActionPerformed

   private void allcheckActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_allcheckActionPerformed
       for (JCheckBox j : colors) {
           j.setSelected(true);
       }

       applyFilters();
   }//GEN-LAST:event_allcheckActionPerformed

   private void quitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_quitActionPerformed
       if (JOptionPane.showConfirmDialog(null, Tools.getLoc(12), Tools.getLoc(13), JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
           System.exit(0);
       }
   }//GEN-LAST:event_quitActionPerformed

   private void closeeditorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeeditorActionPerformed
       if (JOptionPane.showConfirmDialog(null, Tools.getLoc(14), "", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
           this.setVisible(false);
           this.dispose();
       }
   }//GEN-LAST:event_closeeditorActionPerformed

private void _clistKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event__clistKeyPressed
    synchronizeList(0);
    switch (evt.getKeyCode()) {
        case KeyEvent.VK_ADD:
        case KeyEvent.VK_RIGHT:
            addtoDeck();
            break;

        case KeyEvent.VK_SUBTRACT:
        case KeyEvent.VK_LEFT:
            removefromDeck();
            break;

    }
}//GEN-LAST:event__clistKeyPressed

private void _clistValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event__clistValueChanged
    if (_clist.getSelectedIndex() >= 0) {
        showSelected(_clist);
    }
}//GEN-LAST:event__clistValueChanged

private void _decklistValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event__decklistValueChanged
    if (_decklist.getSelectedIndex() >= 0) {
        showSelected(_decklist);
    }
}//GEN-LAST:event__decklistValueChanged

private void _decklistKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event__decklistKeyPressed
    synchronizeList(1);
    switch (evt.getKeyCode()) {
        case KeyEvent.VK_ADD:
        case KeyEvent.VK_RIGHT:
            addtoDeck();
            break;

        case KeyEvent.VK_SUBTRACT:
        case KeyEvent.VK_LEFT:
            removefromDeck();
            break;
    }
}//GEN-LAST:event__decklistKeyPressed

private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
}//GEN-LAST:event_formWindowClosed

private void _showtextdeckActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__showtextdeckActionPerformed
// TODO add your handling code here:
    showTextDeck();
}//GEN-LAST:event__showtextdeckActionPerformed

private void _transferActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__transferActionPerformed
// TODO add your handling code here:
    //transfer();
}//GEN-LAST:event__transferActionPerformed

private void _spellwhiteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__spellwhiteActionPerformed
    // TODO add your handling code here:
}//GEN-LAST:event__spellwhiteActionPerformed

private void _spellredActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__spellredActionPerformed
    // TODO add your handling code here:
}//GEN-LAST:event__spellredActionPerformed

private void _eventblueActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__eventblueActionPerformed
    // TODO add your handling code here:
}//GEN-LAST:event__eventblueActionPerformed

private void _eventredActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__eventredActionPerformed
    // TODO add your handling code here:
}//GEN-LAST:event__eventredActionPerformed

private void _spellblueActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__spellblueActionPerformed
    // TODO add your handling code here:
}//GEN-LAST:event__spellblueActionPerformed

private void _eventwhiteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__eventwhiteActionPerformed
    // TODO add your handling code here:
}//GEN-LAST:event__eventwhiteActionPerformed

private void _clistsortcharItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event__clistsortcharItemStateChanged
    applyFilters();
    showFilteredList();
    showDeckList(-1);
}//GEN-LAST:event__clistsortcharItemStateChanged

private void _exportActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__exportActionPerformed
}//GEN-LAST:event__exportActionPerformed

private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
    Tools.exportCardList(mCardList);
    _export.setSelected(false);
}//GEN-LAST:event_jMenuItem1ActionPerformed

private void _clistsortnoItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event__clistsortnoItemStateChanged
    applyFilters();
    showFilteredList();
    showDeckList(-1);
}//GEN-LAST:event__clistsortnoItemStateChanged

private void _clistsortcostItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event__clistsortcostItemStateChanged
    applyFilters();
    showFilteredList();
    showDeckList(-1);
}//GEN-LAST:event__clistsortcostItemStateChanged

private void _attrallcheckActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__attrallcheckActionPerformed
    for (JCheckBox j : atkattrs) {
        j.setSelected(true);
    }
    for (JCheckBox j : defattrs) {
        j.setSelected(true);
    }
    applyFilters();
}//GEN-LAST:event__attrallcheckActionPerformed

private void _attralluncheckActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__attralluncheckActionPerformed
    for (JCheckBox j : atkattrs) {
        j.setSelected(false);
    }
    for (JCheckBox j : defattrs) {
        j.setSelected(false);
    }
    applyFilters();
}//GEN-LAST:event__attralluncheckActionPerformed

private void _checkruleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__checkruleActionPerformed
        try {
            String url = "http://docs.google.com/View?id=dztqbvp_64gndtdzd8";
            Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url);
        } catch (IOException ex) {
            Logger.getLogger(DeckEditorWindow.class.getName()).log(Level.SEVERE, null, ex);
        }
}//GEN-LAST:event__checkruleActionPerformed

private void _defcActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__defcActionPerformed
    // TODO add your handling code here:
}//GEN-LAST:event__defcActionPerformed

private void _defbActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__defbActionPerformed
    // TODO add your handling code here:
}//GEN-LAST:event__defbActionPerformed

private void _atkbActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__atkbActionPerformed
    // TODO add your handling code here:
}//GEN-LAST:event__atkbActionPerformed

private void _defaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__defaActionPerformed
    // TODO add your handling code here:
}//GEN-LAST:event__defaActionPerformed

private void _atkaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__atkaActionPerformed
    // TODO add your handling code here:
}//GEN-LAST:event__atkaActionPerformed
    /**
     * @param args the command line arguments
     */
  // Variables declaration - do not modify//GEN-BEGIN:variables
  private javax.swing.JTextPane _SCArea;
  private javax.swing.JCheckBox _atka;
  private javax.swing.JCheckBox _atkb;
  private javax.swing.JCheckBox _atkc;
  private javax.swing.JButton _attrallcheck;
  private javax.swing.JButton _attralluncheck;
  private javax.swing.JTabbedPane _attrtab;
  private javax.swing.JTabbedPane _cardtab;
  private javax.swing.JMenuItem _checkrule;
  private javax.swing.JList _clist;
  private javax.swing.ButtonGroup _clistsort;
  private javax.swing.JRadioButton _clistsortchar;
  private javax.swing.JRadioButton _clistsortcost;
  private javax.swing.JRadioButton _clistsortno;
  private javax.swing.JList _decklist;
  private javax.swing.JTextField _deckname;
  private javax.swing.JLabel _decksab;
  private javax.swing.JLabel _decksabline2;
  private javax.swing.JCheckBox _defa;
  private javax.swing.JCheckBox _defb;
  private javax.swing.JCheckBox _defc;
  private javax.swing.JCheckBox _eventblack;
  private javax.swing.JCheckBox _eventblue;
  private javax.swing.JCheckBox _eventgreen;
  private javax.swing.JCheckBox _eventred;
  private javax.swing.JCheckBox _eventwhite;
  private javax.swing.JMenu _export;
  private javax.swing.JButton _showtextdeck;
  private javax.swing.JCheckBox _spellblack;
  private javax.swing.JCheckBox _spellblue;
  private javax.swing.JCheckBox _spellgreen;
  private javax.swing.JPanel _spellpanel;
  private javax.swing.JPanel _spellpanel1;
  private javax.swing.JCheckBox _spellred;
  private javax.swing.JCheckBox _spellwhite;
  private javax.swing.JButton _transfer;
  private javax.swing.JButton allcheck;
  private javax.swing.JButton alluncheck;
  private javax.swing.JLabel amount;
  private javax.swing.JMenuItem closeeditor5;
  private javax.swing.JLabel jLabel20;
  private javax.swing.JLabel jLabel21;
  private javax.swing.JLabel jLabel22;
  private javax.swing.JLabel jLabel23;
  private javax.swing.JLabel jLabel24;
  private javax.swing.JMenu jMenu1;
  private javax.swing.JMenu jMenu6;
  private javax.swing.JMenuBar jMenuBar6;
  private javax.swing.JMenuItem jMenuItem1;
  private javax.swing.JScrollPane jScrollPane1;
  private javax.swing.JScrollPane jScrollPane2;
  private javax.swing.JScrollPane jScrollPane3;
  private javax.swing.JButton loaddeck;
  private javax.swing.JButton newdeck;
  private javax.swing.JMenuItem quit5;
  private javax.swing.JButton savedeck;
  // End of variables declaration//GEN-END:variables
}
